package com.leadbank.bigdata.redis;

import org.apache.commons.lang3.StringUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 刘飞 E-mail:liufei_it@126.com
 *
 * @version 1.0.0
 * @since 2015年11月21日 下午3:39:55
 */
public class Tester {
    
    public static void main21(String[] args) throws Exception {
        String sentinels = "10.14.86.40:26379";
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(5);
        poolConfig.setMinIdle(5);
        poolConfig.setMaxIdle(5);
        poolConfig.setMaxWaitMillis((int) 30000);
        Set<String> sentinelsSet = new HashSet<String>();
        if (StringUtils.isNotBlank(sentinels)) {
            String[] sentinelsSplit = StringUtils.split(sentinels, ",");
            for (String sentinel : sentinelsSplit) {
                sentinelsSet.add(sentinel);
            }
        }
        JedisPool pool = new JedisPool(poolConfig, "10.14.86.40", 6379, (int) 30000, "tongcheng123", 0);
        Jedis jedis = pool.getResource();
        jedis.set("name", "尿性😄哈哈");
        System.out.println(jedis.get("name"));
    }
    
    public static void main(String[] args) throws Exception {
        String sentinels = "10.14.86.40:26379";
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(5);
        poolConfig.setMinIdle(5);
        poolConfig.setMaxIdle(5);
        poolConfig.setMaxWaitMillis((int) 30000);
        Set<String> sentinelsSet = new HashSet<String>();
        if (StringUtils.isNotBlank(sentinels)) {
            String[] sentinelsSplit = StringUtils.split(sentinels, ",");
            for (String sentinel : sentinelsSplit) {
                sentinelsSet.add(sentinel);
            }
        }
        JedisSentinelPool pool = new JedisSentinelPool("infmaster", sentinelsSet, poolConfig, (int) 30000, "tongcheng123", 0);
        Jedis jedis = pool.getResource();
        jedis.set("name", "尿性😄哈哈");
        System.out.println(jedis.get("name"));
    }

    public static void main09(String[] args) {
        DefaultRedisConnectionFactory connectionFactory = new DefaultRedisConnectionFactory();
        connectionFactory.setMasterName("fncmaster");
        connectionFactory.setSentinelEnable(true);
        String sentinels = "10.14.86.42:26379";
        connectionFactory.setSentinels(sentinels);
        connectionFactory.setPassword("tongcheng123");
        connectionFactory.afterPropertiesSet();
        RedisConnection connection = connectionFactory.getConnection();
        connection.getJedis().set("name", "尿性😄哈哈");
        System.out.println(connection.getJedis().get("name"));
    }
}
